package com.ljcalc.business.components;

import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

import com.ljcalc.business.components.fetchers.HistoryResultFetcher;
import com.ljcalc.business.components.requests.HistoryResultRequest;
import com.ljcalc.business.components.requests.SSLHistoryResultRequest;

public class HistoryResultsAnalyzer extends AbstractHistoryResultAnalyzer {

	protected HashMap<String, Combination> resultMap = null;
	protected LinkedList<List<LongAndCounter>> subCombStatList = null;
	protected int MAX_NUMBER;
	protected int COMB_LENGTH;
	
	protected HashMap<String, ConsecutiveSpacePattern> historyPatternMap = null;
	
	private List<Integer> firstNumberTimeConsecutiveStatList = null;
	private List<Integer> lastNumberTimeConsecutiveStatList = null;
	protected long TIME_CONSECUTIVE_TOLERANCE=9;
	protected LinkedList<LongAndCounter> minMaxDiffStatList;
	protected LinkedList<LongAndCounter> minMaxMidDiffStatList;
	protected ResultHistory theInstance = null;
	protected int SUB_COMB_QUANTITY = 21;
	protected int CAC_NUMBER;
	protected long MINMAX_DIFF_TOLERANCE;

	
	protected boolean superInit(ResultHistory theInstance,HistoryResultRequest lastResultRequest){

		
		boolean hasNewResults = false;
		//load the missing one from the Internet
		while(isValidRequest((lastResultRequest = getNextResultRequest(lastResultRequest)))){
			HistoryResultFetcher f = new HistoryResultFetcher(lastResultRequest.getURLStr());
			try {
				f.loadContent();
				List<Combination> list = f.getList();
				if(list==null||list.size()==0){
					break;
				}
				boolean newResult = theInstance.setResults(lastResultRequest.getType(), lastResultRequest.getYear(), lastResultRequest.getRound(), list);
				hasNewResults = newResult || hasNewResults;
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}			
		}
				 
		//write the data it into the local files
		if(hasNewResults){
			theInstance.save(false);
		}
		
		Enumeration keys = theInstance.getAllKeys();
		while(keys.hasMoreElements()){
			String key = (String)keys.nextElement();
			if(key.equals(SSLResultHistories.LATEST_RESULT_KEY)){
				continue;
			}
			HistoryResultRequest r = theInstance.getResultInRequest(key);
			List<Combination> list = theInstance.getResults(key);
			Iterator<Combination> itr = list.iterator();
			int i = 1;
			while(itr.hasNext()){
				resultMap.put(generateResultKeyComb(i, r.getType(), r.getYear(), r.getRound()), (Combination) itr.next());
				i++;
			}
		}
		
		System.out.println(new Date(System.currentTimeMillis())+":"+"a result set with size of "+resultMap.size()+" is initialized.");
		
		System.out.println(new Date(System.currentTimeMillis())+":"+"initializing the history results' patterns.");
		historyPatternMap = getHistoryResultsStat();
		System.out.println(new Date(System.currentTimeMillis())+":"+ historyPatternMap.size() +" appeared in the history results");
		
		System.out.println(new Date(System.currentTimeMillis())+":Gathering first and last number in time consecutive statistics");
		firstNumberTimeConsecutiveStatList = getNumberTimeConsecutiveStat(0);
		lastNumberTimeConsecutiveStatList = getNumberTimeConsecutiveStat(COMB_LENGTH-1);
		
		
		return true;
	}
	

	
	/**
	 * get statistics for adjacent numbers in combination result history
	 * for example 1,2,3
	 * 			   3,4
	 * 
	 * @param index is the number of adjacent number you want to analyzer to get statistic
	 *      if you want find out 2 adjacent number in combinations result like 1,2,4,6,7,8,10
	 *      you set index to 2 this combination has 1,2 which is 2 consecutive numbers
	 *      where 6,7,8 is not because 6,7,8 is 3 consecutive numbers  
	 *      
	 *  @param space is the number difference between to adjacent numbers, 
	 *  	if you want 1,2,3 then set space to 1
	 *      if you want 2,4 pattern then set the space to 2
	 *      
	 * @return the total number of adjacent numbers
	 */
	public ConsecutiveSpacePattern getAdjacentStat(int consecutiveIndex,int space){
		int onlyonce=0;
		int twice = 0;
		int threetimes = 0;
		Collection<String> keyList = resultMap.keySet();
		Iterator<String> itr = keyList.iterator();
		while (itr.hasNext()) {
			String key = (String) itr.next();
			Combination comb = resultMap.get(key);

			ConsecutiveSpacePattern cspSingleComb = getAdjacentStatForSingleComb(comb,consecutiveIndex,space);
			
			onlyonce += cspSingleComb.getOnceCounter();
			twice += cspSingleComb.getTwiceCounter();
			threetimes += cspSingleComb.getThreeTimesCounter();
							
				
		}
		
		
		ConsecutiveSpacePattern csp = new ConsecutiveSpacePattern(consecutiveIndex, space);
		csp.setOnceCounter(onlyonce);
		csp.setTwiceCounter(twice);
		csp.setThreeTimesCounter(threetimes);
//		retlist.add(new Double(100*onlyonce/(double)keyList.size()));
//		retlist.add(new Double(100*twice/(double)keyList.size()));
//		retlist.add(new Double(100*threetimes/(double)keyList.size()));

		
		return csp;
	}
	
	protected ConsecutiveSpacePattern getAdjacentStatForSingleComb(
			Combination comb, int consecutiveIndex, int space) {
		
			ConsecutiveSpacePattern retcsp = new ConsecutiveSpacePattern(consecutiveIndex, space);
			long[] l = comb.getComb();
			long temp=l[0];
			int tempCounter = consecutiveIndex;
			int adjacentcounter = 0;
			for(int i=1;i<comb.getComb().length;i++){
				long n = (l[i]-space);
				if(temp==n){
					tempCounter--;
				}else if((i==(COMB_LENGTH/-1)&&tempCounter==0)||tempCounter==0){
					adjacentcounter++;
				}
				temp=l[i];
			}
			if(adjacentcounter==1){
				retcsp.setOnceCounter(1);
			}
			
			if(adjacentcounter==2){
				retcsp.setTwiceCounter(1);
			}
			if(adjacentcounter==3){
				retcsp.setThreeTimesCounter(1);
			}
		return retcsp;
	}
	
	public boolean isConsecutiveAcceptableCombination(Combination comb){
		
		if(historyPatternMap!=null){
			
			for(int space=1;space<MAX_NUMBER;space++){
				
				for (int consecutiveIndex = 2; consecutiveIndex <= COMB_LENGTH; consecutiveIndex++) {
					ConsecutiveSpacePattern csp = getAdjacentStatForSingleComb(comb, consecutiveIndex, space);
					if(csp.isValid()){
						ConsecutiveSpacePattern hcsp = historyPatternMap.get(csp.getKey());
						if(hcsp!=null){
							int chance3 = hcsp.getThreeTimesCounter();
							int chance2 = hcsp.getTwiceCounter() + chance3;
							int chance1 = hcsp.getOnceCounter() + chance2;
							
							if((csp.getOnceCounter()==1&&chance1<CAC_NUMBER)||
									(csp.getTwiceCounter()==1&&chance2<CAC_NUMBER)||
									(csp.getThreeTimesCounter()==1&&chance3<CAC_NUMBER)){
								return false;
							}
						}else{
							// this means that in the history there hasn't been a pattern like this appeared before.
							return false;
						}
					}
				}
			}
		}else{
			System.out.println("HIstory pattern map is not properly initialized.");
		}
		return true;
		
	}
	
	/**
	 * 
	 * @return the occurrence of percentage for every lotto number 
	 */
	public List<NumberPercentage> getLottoStat(){
		List<NumberPercentage> retList = new LinkedList<NumberPercentage>();
		for(int i=1;i<=MAX_NUMBER;i++){
			int counter=0;
			Collection<String> keyList = resultMap.keySet();
			Iterator<String> itr = keyList.iterator();
			while (itr.hasNext()) {
				String key = (String) itr.next();
				Combination comb = resultMap.get(key);
				long[] l = comb.getComb();
				for(int j=0;j<comb.getComb().length;j++){
					if(l[j]==i){
						counter++;
						break;
					}
				}
			}
			retList.add(new NumberPercentage(i,(1000*counter)/keyList.size()));
		}
		
		Collections.sort(retList,new Comparator<NumberPercentage>() {

			public int compare(NumberPercentage o1, NumberPercentage o2) {
				return (int) (o2.getPercentage()-o1.getPercentage());
			}
		});
		
		return retList;
	}
	

	public HistoryResultRequest getNextResultRequest(HistoryResultRequest r) {
		return null;
	}

	public List<Integer> getNumberTimeConsecutiveStat(int theindex) {
		return null;
	}

	public List<Combination> getResult() {
		return null;
	}


	public boolean initHistoryResults() {
		return false;
	}


	public boolean isValidRequest(HistoryResultRequest lastResultRequest) {
		return false;
	}

	
	public boolean isInTimeConsecutiveTolerance(Combination combToCompare){
		
		Combination comb = getLatestResultCombination();
		long diff = Math.abs(combToCompare.getComb()[0]-comb.getComb()[0]);
		if(diff>TIME_CONSECUTIVE_TOLERANCE){
			return false;
		}
		
		diff = Math.abs(combToCompare.getComb()[COMB_LENGTH-1]-comb.getComb()[COMB_LENGTH-1]);
		if(diff>TIME_CONSECUTIVE_TOLERANCE){
			return false;
		}
		
		diff = Math.abs(combToCompare.getComb()[COMB_LENGTH/2+1]-comb.getComb()[COMB_LENGTH/2+1]);
		if(diff>12){
			return false;
		}
		return true;
	}
	
	private Combination getLatestResultCombination() {
		HistoryResultRequest hrr = theInstance.getLatestResultInRequest();
		
		List retL = getResult(hrr.getType(), hrr.getYear(), hrr.getRound());
				
		if(retL.size()>0){
			return (Combination) retL.get(retL.size()-1);
		}
		return null;
	}


	public LinkedHashMap<String, Combination> sortResultMap(HashMap map){
		List<Combination> valueList = new ArrayList<Combination>(map.values());
		Collection<String> keyList = map.keySet();
	
		Collections.sort(valueList, new Comparator(){
			public int compare(Object arg0, Object arg1) {
				long[] comb1 = ((Combination)arg0).getComb();
				long[] comb2 = ((Combination)arg1).getComb();
				
				for(int i=0;i<comb1.length;i++){
					int ret = (int) (comb1[i] - comb2[i]);
					if(ret!=0){
						return ret;
					}
				}
				return 0;
			}
		});
		
		LinkedHashMap<String, Combination> sortMap = new LinkedHashMap<String, Combination>();

		Iterator<Combination> valueItr = valueList.iterator();
		while (valueItr.hasNext()) {
			Combination combination = (Combination) valueItr.next();
			
			Iterator<String> keyItr = keyList.iterator();
			LinkedList<String> l = new LinkedList<String>();
			while (keyItr.hasNext()) {
				String key = (String) keyItr.next();

				if(combination.equals(resultMap.get(key))){
					l.add(key);
					if(l.size()>1){
						System.out.println(l + " " + combination);
					}
					sortMap.put(key,combination);
					
				}
				
			}
			
		}
		
//		System.out.println(sortMap);
		
		return sortMap;
	}

	/*
	 * the result contains two combinations, combination 1 and combination 2
	 */
	public List<Combination> getResult(int type, int year, int week){
		List<Combination> ret = new LinkedList<Combination>();
		Object obj1 = null;
		int i = 1;
		while((obj1 = resultMap.get(generateResultKeyComb(i,type,year,week)))!=null){
			ret.add((Combination) obj1);
			i++;
		}
		return ret;
	}
	
	
	protected List<Integer> getNumberTimeConsecutiveStatSuper(int theindex, 
			 HistoryResultRequest hrr2, List<Combination> firstResults) {
		List<Integer> retList = new ArrayList<Integer>();
		for (int i = 0; i < MAX_NUMBER; i++) {
			retList.add(new Integer(0));
		}
		
		long lastNumber = 0;
		
		Iterator<Combination> itrFirst = firstResults.iterator();
		if (itrFirst.hasNext()) {
			Combination comb = itrFirst.next();
			lastNumber = (comb.getComb())[theindex]; 
		}
		
		HistoryResultRequest hrr = hrr2;
		
		while (isValidRequest(hrr=getNextResultRequest(hrr))) {
		
			List<Combination> results = getResult(hrr.getType(), hrr.getYear(), hrr.getRound());
			
			Iterator<Combination> itr = results.iterator();
			if (itr.hasNext()) {
				Combination comb = itr.next();
				long tempNumber = (comb.getComb())[theindex];
				int index = (int) Math.abs(tempNumber-lastNumber);
				if(index==MAX_NUMBER){
					int ja=0;
					ja++;
				}
				retList.set(index, Integer.valueOf(retList.get(index).intValue()+1));
				lastNumber = tempNumber;
			}
			
			if (itr.hasNext()) {
				Combination comb = itr.next();
				long tempNumber = (comb.getComb())[theindex];
				int index = (int) Math.abs(tempNumber-lastNumber);
				retList.set(index, Integer.valueOf(retList.get(index).intValue()+1));
				lastNumber = tempNumber;
			}
		}
		
		return retList;
	}
	
	
	
	public boolean hasSameCombInHistory(Combination comb){
		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return false;
		}
		
		List<Combination> valueList = new ArrayList<Combination>(resultMap.values());
		
		if(valueList.contains(comb)){
			return true;
		}
		
		
		return false;
	}
	/**
	 * analyze all the consecutive patterns that appeared in the history
	 * @return
	 */
	public HashMap<String,ConsecutiveSpacePattern> getHistoryResultsStat(){
		HashMap<String, ConsecutiveSpacePattern> map = new HashMap<String, ConsecutiveSpacePattern>();
		for(int space=1;space<MAX_NUMBER;space++){
		
			for (int i = 2; i <= COMB_LENGTH; i++) {
				ConsecutiveSpacePattern csp = getAdjacentStat(i,space);
				if(csp.isValid()){
					System.out.println(csp);
					map.put(csp.getKey(),csp);
				}
			}
		}

		return map;		
	}
	


	
	public boolean isInMinMaxDiffTolerance(Combination comb) {
		LongAndCounter lac = new LongAndCounter(comb.getComb()[comb.getComb().length-1]-comb.getComb()[0]);
		return minMaxDiffStatList.indexOf(lac)!=-1;
	}

	public boolean isInMinMaxDiffMidTolerance(Combination comb) {
		LongAndCounter lac = new LongAndCounter(comb.getComb()[comb.getComb().length-1] + comb.getComb()[0]
		                        - 2*comb.getComb()[comb.getComb().length/2+1] );
		return minMaxMidDiffStatList.indexOf(lac)!=-1;
	}

	public HistoryResultRequest getHistoryResultRequestFromKey(String key){
		int startIndex =  0;
		int underScoreIndex = key.indexOf('_');
		int year = Integer.valueOf(key.substring(startIndex, underScoreIndex));
		startIndex = underScoreIndex;
		underScoreIndex = key.substring(startIndex+1,key.length()).indexOf('_') + startIndex+1;
		int round = Integer.valueOf(key.substring(startIndex+1, underScoreIndex));
		startIndex = underScoreIndex+1;
		underScoreIndex = key.substring(startIndex+1,key.length()).indexOf('_') + startIndex+1;
		int type = Integer.valueOf(key.substring(startIndex, underScoreIndex));
    	return new SSLHistoryResultRequest(type, year, round);
	}
	
	public HashMap<String, Combination> getHistorySimilarities(Combination comb,
			HistoryResultRequest sslhrr, int tolerance) {
		
		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return null;
		}
		
		HashMap<String,Combination> valueMap = new HashMap<String, Combination>();
		Collection<String> keyList = resultMap.keySet();
		
		Iterator<String> keyItr = keyList.iterator();
		while (keyItr.hasNext()) {
			String key = keyItr.next();
			if(getHistoryResultRequestFromKey(key).compareTo(sslhrr)<0){				
				Combination tcomb = resultMap.get(key);
				int counter = 0;
				for(int i=0;i<comb.getComb().length;i++){
					long n = comb.getComb()[i];
					for (int j = 0; j < tcomb.getComb().length; j++) {
						long m = tcomb.getComb()[j];
						if(n==m){
							counter++;
							break;
						}				
					}
				}
				if(counter>=tolerance&&counter!=tcomb.getComb().length){
					valueMap.put(key, tcomb);
				}	
			}
		}
		
		if(valueMap.size()>0){
			return valueMap;
		}
		
		
		return null;

	}
	
	public int getAverageSubCombOccurenceTimes(Combination comb){
		
		int counter = 0;
		long[] la = comb.getComb();
		for (int i = 0; i < la.length-1; i++) {
			long l = la[i];
			List<LongAndCounter> tmpList = subCombStatList.get((int) (l-1));
			for (int j = i+1; j < la.length; j++) {
				Long lb = new Long( la[j]);
				int index = tmpList.indexOf(new LongAndCounter(lb));
				if(index!=-1){
					counter += tmpList.get(index).getCounter();
				}
			}
		}

		
		return counter/SUB_COMB_QUANTITY ;
	}
	
	/**
	 * get the sub combination statistics in the history
	 * sub combination is the combinations that has length 
	 * less than the standard combination length.
	 * 
	 * @return
	 */
	public Collection<List<LongAndCounter>> getHistorySubCombinationStat(){
		
		if(subCombStatList!=null){
			return subCombStatList;
		}
		
		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return null;
		}
		
		Collection<String> keyList = resultMap.keySet();
		Iterator<String> keyItr = keyList.iterator();
		LinkedList<List<LongAndCounter>> retList = new LinkedList<List<LongAndCounter>>();
		for (int i = 0; i < MAX_NUMBER+10; i++) {
			retList.add( new LinkedList<LongAndCounter>());
			
		}
		int totalCounter =0;
		int keySetCounter = 0;
		boolean recorder = true;
		int subCombCounter = 0;
		int singleCounter = 0;
		while (keyItr.hasNext()) {
			String key = keyItr.next();
			keySetCounter++;
			Combination tcomb = resultMap.get(key);
			long[] la = tcomb.getComb();
			for (int i = 0; i < la.length-1; i++) {
				long l = la[i];
				if(l>MAX_NUMBER){
					//i am not interested in it
					break;
				}				
				List<LongAndCounter> list = retList.get((int) l-1);
				for (int j = i+1; j < la.length; j++) {
					totalCounter++;
					if(recorder){
						singleCounter++;
					}
					Long lb = new Long( la[j]);
					if(lb.longValue()>MAX_NUMBER){
						//i am not interested in it
						break;
					}	
					int index = list.indexOf(new LongAndCounter(lb));
					if(index!=-1){
						list.get(index).increment();
					}else{
						list.add(new LongAndCounter(lb));
						subCombCounter++;
					}
					
				}
			}
			recorder = false;
		}
		
		System.out.println();
		System.out.println("total counter = " +totalCounter);
		
		System.out.println();
		System.out.println("keyset counter = " +keySetCounter);
		
		System.out.println();
		System.out.println("single counter = " +singleCounter);
		
		System.out.println();
		System.out.println("SubComb counter = " +subCombCounter);
		subCombStatList = retList;
		
		return retList;
	}
	
	public LinkedList<LongAndCounter> getHistoryMaxMinMidDiffStat(){

		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return null;
		}
				
		
		LinkedList<Long> retList = new LinkedList<Long>();
		Collection<String> keyList = resultMap.keySet();
		
		Iterator<String> keyItr = keyList.iterator();
		while (keyItr.hasNext()) {
			String key = keyItr.next();
			Combination tcomb = resultMap.get(key);
			if(tcomb.getComb()[tcomb.getComb().length-1]>MAX_NUMBER){
				continue;
			}
			long midIndex = tcomb.getComb().length/2 + 1;
			retList.add(new Long((tcomb.getComb()[tcomb.getComb().length-1]-tcomb.getComb()[(int) midIndex] - 
					tcomb.getComb()[(int) midIndex]+tcomb.getComb()[0])));
		}
		LinkedList<LongAndCounter> statList = new LinkedList<LongAndCounter>();
		
		Iterator<Long> itr = retList.iterator();
		while (itr.hasNext()) {
			Long l = (Long) itr.next();
			LongAndCounter lc = new LongAndCounter(l.longValue());
			int index = 0;
			if((index=statList.indexOf(lc))!=-1){
				statList.get(index).increment();
			}else if(lc.getLong()<=34){
				statList.add(lc);
			}			
		}
		Collections.sort(statList, new Comparator<Object>() {

			public int compare(Object o1, Object o2) {
				LongAndCounter lc1 = (LongAndCounter)o1;
				LongAndCounter lc2 = (LongAndCounter)o2;
				
				return lc1.getCounter()-lc2.getCounter();
			}
		});
		
		LinkedList<LongAndCounter> resultList = new LinkedList<LongAndCounter>();
		long counter = 0;
		for (int i = 0; i < statList.size(); i++) {
			LongAndCounter lace = statList.get(i);
			counter += lace.getCounter();
			if(counter<(resultMap.size()/10)){
				System.out.println(lace);
			}else{
				resultList.add(lace);
			}
			
		}
		
		return resultList;
	}
	

	public LinkedList<LongAndCounter> getHistoryMaxMinDiffStat(){

		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return null;
		}
		LinkedList<Long> retList = new LinkedList<Long>();
		Collection<String> keyList = resultMap.keySet();
		
		Iterator<String> keyItr = keyList.iterator();
		while (keyItr.hasNext()) {
			String key = keyItr.next();
			Combination tcomb = resultMap.get(key);
			if(tcomb.getComb()[tcomb.getComb().length-1]>MAX_NUMBER){
				continue;
			}
			retList.add(new Long((tcomb.getComb()[tcomb.getComb().length-1]-tcomb.getComb()[0])));
		}
		
		LinkedList<LongAndCounter> statList = new LinkedList<LongAndCounter>();
		Iterator<Long> itr = retList.iterator();
		while (itr.hasNext()) {
			Long l = (Long) itr.next();
			LongAndCounter lc = new LongAndCounter(l.longValue());
			int index = 0;
			if((index=statList.indexOf(lc))!=-1){
				statList.get(index).increment();
			}else if(lc.getLong()<=34){
				statList.add(lc);
			}			
		}
		Collections.sort(statList, new Comparator<Object>() {

			public int compare(Object o1, Object o2) {
				LongAndCounter lc1 = (LongAndCounter)o1;
				LongAndCounter lc2 = (LongAndCounter)o2;
				
				return lc1.getCounter()-lc2.getCounter();
			}
		});
		LinkedList<LongAndCounter> resultList = new LinkedList<LongAndCounter>();
		long counter = 0;
		for (int i = 0; i < statList.size(); i++) {
			LongAndCounter lace = statList.get(i);
			counter += lace.getCounter();
			if(counter<MINMAX_DIFF_TOLERANCE){
				System.out.println(lace);
//				statList.remove(lace);
			}else{
				resultList.add(lace);
			}
		}
		
		System.out.println();
		return resultList;
	}
	
	/**
	 * 
	 * @param comb
	 * @param tolerance number of items that are same
	 * @return
	 */
	public HashMap<String, Combination> getHistorySimilarities(Combination comb, int tolerance) {
		if(!(resultMap instanceof LinkedHashMap<?, ?>)){
			//it is not intialized yet
			return null;
		}
		
		HashMap<String,Combination> valueMap = new HashMap<String, Combination>();
		Collection<String> keyList = resultMap.keySet();
		
		Iterator<String> keyItr = keyList.iterator();
		while (keyItr.hasNext()) {
			String key = keyItr.next();
			Combination tcomb = resultMap.get(key);
			int counter = 0;
			for(int i=0;i<comb.getComb().length;i++){
				long n = comb.getComb()[i];
				for (int j = 0; j < tcomb.getComb().length; j++) {
					long m = tcomb.getComb()[j];
					if(n==m){
						counter++;
						break;
					}				
				}
			}
			if(counter>=tolerance&&counter!=tcomb.getComb().length){
				valueMap.put(key, tcomb);
			}	
		}
		
		if(valueMap.size()>0){
			return valueMap;
		}
		
		
		return null;
	}
	
	protected String generateResultKeyComb(int i, int type, int year, int week) {
		return year+"_"+week+"_"+type+"_"+"comb"+i;		
	}



	public int getMaxNumber() {
		// TODO Auto-generated method stub
		return MAX_NUMBER;
	}



	public int getCombType() {
		if(this instanceof SSLHistoryResultsAnalyzer){
			return ResultHistory.SSL_TYPE;
		}else if(this instanceof SPTTHistoryResultsAnalyzer){
			return ResultHistory.SPTT_TYPE;
		}
		return 0;
	}
}
